import request from '@/utils/request'

// 查询竞赛试题列表
export function listCompetitionTopic(query) {
  return request({
    url: '/race/competitionTopic/list',
    method: 'get',
    params: query
  })
}

// 根据竞赛ID查询试题列表
export function listCompetitionTopicByCompetition(competitionId) {
  return request({
    url: '/race/competitionTopic/listByCompetition/' + competitionId,
    method: 'get'
  })
}

// 查询竞赛试题详细
export function getCompetitionTopic(id) {
  return request({
    url: '/race/competitionTopic/' + id,
    method: 'get'
  })
}

// 新增竞赛试题
export function addCompetitionTopic(data) {
  return request({
    url: '/race/competitionTopic',
    method: 'post',
    data: data
  })
}

// 上传竞赛试题文件
export function uploadCompetitionTopic(file, competitionId) {
  const formData = new FormData()
  formData.append('file', file)
  formData.append('competitionId', competitionId)
  
  return request({
    url: '/race/competitionTopic/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 修改竞赛试题
export function updateCompetitionTopic(data) {
  return request({
    url: '/race/competitionTopic',
    method: 'put',
    data: data
  })
}

// 删除竞赛试题
export function delCompetitionTopic(ids) {
  return request({
    url: '/race/competitionTopic/' + ids,
    method: 'delete'
  })
}

// 获取文件预签名URL
export function getPresignedUrl(bucket, object, expires = 3600) {
  return request({
    url: '/race/minio/presign',
    method: 'get',
    params: { bucket, object, expires }
  })
}
